#include "SystemHead.h"
void main()
{
    int fd_first[2];
    int fd_second[2];
    if(pipe(fd_first)==-1)
    {
        perror("pipe");
    }
    if(pipe(fd_second)==-1)
    {
        perror("pipe");
    }
    pid_t pid;
    pid=fork();
    if(pid<0)
    {
        perror("fork");
        exit(-1);
    }
    // fcntl(fd[0],F_SETFL,O_NONBLOCK);
    if(pid==0)
    {
        while(1)
        {

            char buff[1024]={0};
            read(fd_first[0],buff,sizeof(buff));
            printf("parent %s\n",buff);
            memset(buff,0,sizeof(buff));
            scanf("%[^\n]",buff);
            getchar();
            write(fd_second[1],buff,sizeof(buff));
        }
    }
    else
    {
        while(1)
        {
            char buff[1024]={0};
            memset(buff,0,sizeof(buff));
            scanf("%[^\n]",buff);
            getchar();
            write(fd_first[1],buff,sizeof(buff));
            read(fd_second[0],buff,sizeof(buff));
            printf("child %s\n",buff);  
        }
    }
}